"""Setup the pglite application"""
import logging

from pglite import model
from pglite.config.environment import load_environment
from pglite.model import meta

log = logging.getLogger(__name__)

def setup_app(command, conf, vars):
    """Place any commands to setup pglite here"""
    load_environment(conf.global_conf, conf.local_conf)

    # Drop existing tables
    log.info("Removing tables ...")
    meta.metadata.drop_all(bind=meta.engine)
    log.info("Removed")
    
    # Create the tables if they don't already exist
    log.info("Creating tables...")
    meta.metadata.create_all(bind=meta.engine)
    log.info("Successfully set up.")

    srv = model.Server(name="Kael'thas", zone="EU")
    meta.Session.add(srv)
    guild = model.Guild(name="Rouge",faction="A",status=1,website_url="http://www.guilde-rouge.com")
    guild.server = srv
    meta.Session.add(guild)
    admin = model.User(login="Jullye", password="16777216", email="tfalise.public@gmail.com", type="A")
    admin.guild = guild
    meta.Session.add(admin)
    
    meta.Session.commit()